package com.steve.xfood.util;

import com.steve.xfood.enums.CodeEnum;

/**
 * 通过一个code值，获取枚举的内容
 * @author steve
 * @date 2020/5/20 15:06
 */
public class EnumUtil {

    public static <T extends CodeEnum> T getByCode(Integer code, Class<T> enumClass) {
        for (T each: enumClass.getEnumConstants()) {
            if (code.equals(each.getCode())) {
                //如果code值和枚举的code一致，则返回枚举
                return each;
            }
        }
        return null;
    }
}
